<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the startRecorder method from the FlutterSoundRecorder class, for the Dart programming language.">
  <title>startRecorder method - FlutterSoundRecorder class - flutter_sound_recorder library - Dart API</title>


  
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet">
  
  <link rel="stylesheet" href="../../static-assets/github.css?v1">
  <link rel="stylesheet" href="../../static-assets/styles.css?v1">
  <link rel="icon" href="../../static-assets/favicon.png?v1">
  
</head>

<body data-base-href="../../" data-using-base-href="false" class="light-theme">
<div id="overlay-under-drawer"></div>
<header id="title">
  <span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="../../index.html">flutter_sound</a></li>
    <li><a href="../../public_flutter_sound_recorder">public&#47;flutter_sound_recorder.dart</a></li>
    <li><a href="../../public_flutter_sound_recorder/FlutterSoundRecorder-class.html">FlutterSoundRecorder</a></li>
    <li class="self-crumb">startRecorder method</li>
  </ol>
  <div class="self-name">startRecorder</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
  <div class="toggle" id="theme-button" title="Toggle brightness">
    <label for="theme">
      <input type="checkbox" id="theme" value="light-theme">
      <span id="dark-theme-button" class="material-symbols-outlined">
        dark_mode
      </span>
      <span id="light-theme-button" class="material-symbols-outlined">
        light_mode
      </span>
    </label>
  </div>
</header>
<main>
<div
    id="dartdoc-main-content"
    class="main-content"
    data-above-sidebar="public_flutter_sound_recorder&#47;FlutterSoundRecorder-class-sidebar.html"
    data-below-sidebar="">
    <div>
<h1><span class="kind-method">startRecorder</span> method 
</h1></div>

    <section class="multi-line-signature">
      
<span class="returntype"><a href="https://api.flutter.dev/flutter/dart-core/Future-class.html">Future</a><span class="signature">&lt;<wbr><span class="type-parameter">void</span>&gt;</span></span>
<span class="name ">startRecorder</span>(<wbr>{<ol class="parameter-list"> <li><span class="parameter" id="startRecorder-param-codec"><span class="type-annotation"><a href="https://pub.dev/documentation/flutter_sound_platform_interface/9.28.0/flutter_sound_platform_interface/Codec.html">Codec</a></span> <span class="parameter-name">codec</span> = <span class="default-value">Codec.defaultCodec</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-toFile"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/String-class.html">String</a>?</span> <span class="parameter-name">toFile</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-toStreamFloat32"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-async/StreamSink-class.html">StreamSink</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-typed_data/Float32List-class.html">Float32List</a></span>&gt;</span></span>&gt;</span>?</span> <span class="parameter-name">toStreamFloat32</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-toStreamInt16"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-async/StreamSink-class.html">StreamSink</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-typed_data/Int16List-class.html">Int16List</a></span>&gt;</span></span>&gt;</span>?</span> <span class="parameter-name">toStreamInt16</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-toStream"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-async/StreamSink-class.html">StreamSink</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-typed_data/Uint8List-class.html">Uint8List</a></span>&gt;</span>?</span> <span class="parameter-name">toStream</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-sampleRate"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/int-class.html">int</a>?</span> <span class="parameter-name">sampleRate</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-numChannels"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/int-class.html">int</a></span> <span class="parameter-name">numChannels</span> = <span class="default-value">1</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-bitRate"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/int-class.html">int</a></span> <span class="parameter-name">bitRate</span> = <span class="default-value">16000</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-bufferSize"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/int-class.html">int</a></span> <span class="parameter-name">bufferSize</span> = <span class="default-value">8192</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-enableVoiceProcessing"><span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">enableVoiceProcessing</span> = <span class="default-value">false</span>, </span></li>
<li><span class="parameter" id="startRecorder-param-audioSource"><span class="type-annotation"><a href="https://pub.dev/documentation/flutter_sound_platform_interface/9.28.0/flutter_sound_platform_interface/AudioSource.html">AudioSource</a></span> <span class="parameter-name">audioSource</span> = <span class="default-value">AudioSource.defaultSource</span>, </span></li>
</ol>})

      

    </section>
    
<section class="desc markdown">
  <p><code>startRecorder()</code> starts recording a recorder.</p>
<hr>
<p>If an <a href="../../public_flutter_sound_recorder/FlutterSoundRecorder/openRecorder.html">openRecorder()</a> is in progress, <code>startRecorder()</code> will automatically wait the end of the opening.</p>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong><em>codec:</em></strong> The codec to be used. Please refer to the <a href="/tau/guides/guides_codecs.html">Codec compatibility Table</a> to know which codecs are currently supported.</li>
<li>One of the following parameters
<ul>
<li><strong><em>toFile:</em></strong> a path to the file being recorded or the name of a temporary file (without slash '/').</li>
<li><strong><em>toStream:</em></strong> if you want to record to a Dart Stream interleaved. Please look to <a href="/tau/guides/guides_live_streams.html">the following notice</a>.</li>
<li><strong><em>toStreamFloat32:</em></strong> if you want to record to a Dart Stream <strong>NOT</strong> interleaved with a Float32 coding. Please look to <a href="/tau/guides/guides_live_streams.html">the following notice</a>.</li>
<li><strong><em>toStreamInt16:</em></strong> if you want to record to a Dart Stream <strong>NOT</strong> interleaved with a Int16 coding. Please look to <a href="/tau/guides/guides_live_streams.html">the following notice</a>.</li>
</ul>
</li>
<li><strong><em>sampleRate:</em></strong> The sample rate in Hertz (used only with PCM codecs)</li>
<li><strong><em>numChannels:</em></strong> The number of channels (1=monophony, 2=stereophony) (used only with PCM codecs)</li>
<li><strong><em>bitRate:</em></strong> The bit rate in Hertz. Optional</li>
<li><strong><em>audioSource</em></strong> : possible value is :
<ul>
<li>defaultSource</li>
<li>microphone</li>
<li>voiceDownlink <em>(if someone can explain me what it is, I will be grateful ;-) )</em></li>
</ul>
</li>
</ul>
<p>Hint: <a href="https://pub.dev/packages/path_provider">path_provider</a> can be useful if you want to get access to some directories on your device.
To record a temporary file, the App can specify the name of this temporary file (without slash) instead of a real path.</p>
<p>Flutter Sound does not take care of the recording permission. It is the App responsability to check or require the Recording permission.
<a href="https://pub.dev/packages/permission_handler">Permission_handler</a> is probably useful to do that.</p>
<h2 id="example">Example</h2>
<pre class="language-dart"><code class="language-dart">    // Request Microphone permission if needed
    PermissionStatus status = await Permission.microphone.request();
    if (status != PermissionStatus.granted)
            throw RecordingPermissionException("Microphone permission not granted");

    await myRecorder.startRecorder(toFile: 'foo', codec: t_CODEC.CODEC_AAC,); // A temporary file named 'foo'
</code></pre>
<h2 id="see-also">See also</h2>
<ul>
<li><a href="../../public_flutter_sound_recorder/FlutterSoundRecorder/stopRecorder.html">stopRecorder()</a></li>
</ul>
<hr>
</section>


    
<section class="summary source-code" id="source">
  <h2><span>Implementation</span></h2>
  <pre class="language-dart"><code class="language-dart">Future&lt;void&gt; startRecorder({
  Codec codec = Codec.defaultCodec,
  String? toFile,
  StreamSink&lt;List&lt;Float32List&gt;&gt;? toStreamFloat32,
  StreamSink&lt;List&lt;Int16List&gt;&gt;? toStreamInt16,
  StreamSink&lt;Uint8List&gt;? toStream,
  int? sampleRate,
  int numChannels = 1,
  int bitRate = 16000,
  int bufferSize = 8192,
  bool enableVoiceProcessing = false,
  AudioSource audioSource = AudioSource.defaultSource,
}) async {
  _logger.d(&#39;FS:---&gt; startRecorder &#39;);

  if ((codec == Codec.pcm16 || codec == Codec.pcmFloat32) &amp;&amp;
      (toStream != null ||
          toStreamFloat32 != null ||
          toStreamInt16 != null) &amp;&amp;
      (!kIsWeb) &amp;&amp;
      Platform
          .isIOS) &#47;&#47; This hack is just to have recorder to stream working correctly.
  {
    FlutterSoundRecorder recorder = FlutterSoundRecorder();
    await recorder.openRecorder();
    try {
      await recorder.startRecorder(
        codec: Codec.aacMP4,
        toFile: &quot;FlutterSound.mp4&quot;,
        audioSource: audioSource,
      );
    } catch (e) {
      _logger.d(&#39;Hacking the bug we have on iOS when recording to stream&#39;);
    }
    await recorder.stopRecorder();
    await recorder.closeRecorder();
  }

  await stopRecorder(); &#47;&#47; No two recorders at the same time
  if (sampleRate == null) {
    sampleRate = await getSampleRate();
    if (sampleRate == 0) {
      sampleRate = 16000;
    }
  }

  await _lock.synchronized(() async {
    await _startRecorder(
      codec: codec,
      toFile: toFile,
      toStream: toStream,
      toStreamFloat32: toStreamFloat32,
      toStreamInt16: toStreamInt16,
      &#47;&#47;timeSlice: timeSlice,
      sampleRate: sampleRate!,
      numChannels: numChannels,
      bitRate: bitRate,
      bufferSize: bufferSize,
      enableVoiceProcessing: enableVoiceProcessing,
      audioSource: audioSource,
    );
  });
  _logger.d(&#39;FS:&lt;--- startRecorder &#39;);
}</code></pre>
</section>


  </div> <!-- /.main-content -->
  <div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
    <!-- The search input and breadcrumbs below are only responsively visible at low resolutions. -->
<header id="header-search-sidebar" class="hidden-l">
  <form class="search-sidebar" role="search">
    <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
    <li><a href="../../index.html">flutter_sound</a></li>
    <li><a href="../../public_flutter_sound_recorder">flutter_sound_recorder</a></li>
    <li><a href="../../public_flutter_sound_recorder/FlutterSoundRecorder-class.html">FlutterSoundRecorder</a></li>
    <li class="self-crumb">startRecorder method</li>
</ol>

    <h5>FlutterSoundRecorder class</h5>
    <div id="dartdoc-sidebar-left-content"></div>
  </div><!--/.sidebar-offcanvas-->
  <div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
</div><!--/.sidebar-offcanvas-->
</main>
<footer>
  <span class="no-break">
    flutter_sound
      9.28.0
  </span>
  
</footer>


<script src="../../static-assets/highlight.pack.js?v1"></script>
<script src="../../static-assets/docs.dart.js"></script>

</body>
</html>

